package cc.magicjson.spring.exploration.annotation.role.aop.advisor;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.stereotype.Component;

/**
 * 自定义的通知类，用于在非Spring框架类的方法执行前后进行日志记录
 *
 * @author <a href="mailto:it_magicjson@163.com">MagicJson</a>
 */

@Component
public class RegularAdvice implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        if (invocation.getThis() != null && !invocation.getThis().getClass().getName().startsWith("org.springframework")) {
            System.out.println("Regular advice - Before method execution");
            Object result = invocation.proceed();
            System.out.println("Regular advice - After method execution");
            return result;
        }

        return invocation.proceed();
    }
}
